package dbTools.coeModel.modelElement.demos.demo1;

import projectsupporter.common.logic.GlobalInfo;
import dbTools.coeModel.annotation.FillItem;
import dbTools.coeModel.modelElement.AbstractReplaceElement;
import dbTools.tableInfo.info.TableInfo;

public class DemoService1 extends AbstractReplaceElement {

	@FillItem(itemName = "<##MAST_NAME##>")
	public String fillItemTest(TableInfo tableInfo)
	{
		return tableInfo.getTableName();
	}
	
	@FillItem(itemName = "<##MAST_ID##>")
	public String fillItemTest2(TableInfo tableInfo)
	{
		return tableInfo.getKey();
	}
	
	@FillItem(itemName = "<##MAST_FIELD##>")
	public String fillItemTest3(TableInfo tableInfo)
	{
		return tableInfo.getTableId().toLowerCase();
	}
	
	@FillItem(itemName = "<##PRJ_NAME##>")
	public String fillItemTest4(TableInfo tableInfo)
	{
		return GlobalInfo.PRJ_NAME.toLowerCase();
	}

	@Override
	public String getFileName(TableInfo tableInfo) {
		return "Config-"+tableInfo.getTableId().toLowerCase()+"-master.xml";
	}

	@Override
	public String getFilePath(TableInfo tableInfo) {
		return GlobalInfo.PRJ_NAME+"/config/configs/spring/master";
	}

	@FillItem(itemName = "<##OBJID##>")
	public String fillItemTest5(TableInfo tableInfo)
	{
		StringBuffer code= new StringBuffer();
		
		if(tableInfo.getKeyFields().size()==1)
		{
			code.append("<value>"+tableInfo.getKey()+"</value>\r\n");
		}
		else
		{
			code.append("<ref bean=\""+tableInfo.getKey()+"Id"+"\" />");
		}
			
		
		
		return code.toString();
	}

}
